<template>
  <div id="messagebox">
    <el-row>
      <el-button type="text" @click="open">打开 Message Box</el-button>
    </el-row>
    <hr>
    <el-row>
      <el-button type="text" @click="open3">打开 Message Box</el-button>
    </el-row>
    <hr>
    <el-row>
      <el-button type="text" @click="open6">打开 Message Box</el-button>
    </el-row>
  </div>
</template>

<script>
export default {
  data () {
    return {
      msg: ''
    }
  },
  methods: {
    open () {
      this.$alert('这是一段内容', '标题名称', {
        confirmButtonText: '确定',
        callback: action => {
          this.$message({
            type: 'info',
            message: `action: ${action}`
          })
        }
      })
    },
    open3 () {
      this.$prompt('请输入邮箱', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
        inputErrorMessage: '邮箱格式不正确'
      }).then(({ value }) => {
        this.$message({
          type: 'success',
          message: '你的邮箱' + value
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        })
      })
    },
    open6 () {
      this.$confirm('检测到未保存的内容，是否在离开页面前保存修改？', '确认信息', {
        distinguishCancelAndClose: true,
        confirmButtonText: '保存',
        cancelButtonText: '放弃修改',
        center: true
      }).then(() => {
        this.message({
          type: 'info',
          message: '保持修改'
        })
      }).catch(action => {
        this.$message({
          type: 'info',
          message: action === 'cancel' ? '放弃保存并离开页面' : '停留在当前页面'
        })
      })
    }
  }
}
</script>
